package com.reform.mapper;

import com.reform.pojo.project.Project;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.reform.pojo.project.SimplifyProject;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 * 项目基本信息 Mapper 接口
 * </p>
 *
 * @author mortale
 * @since 2021-07-20
 */
@Mapper
public interface ProjectMapper extends BaseMapper<Project> {

    /**
     * 获取教师暂存项目
     *
     * @param gh 教师工号
     * @return List<SimplifyProject>
     */
    List<SimplifyProject> getInitiationInfo(@Param("gh") String gh, @Param("type") Integer type);

    @Update("update project set pro_approval = ${proApproval}, pro_status = ${proStatus} where pro_id = #{proId}")
    void updateProByProId(@Param("proId") String proId, @Param("proApproval") Integer proApproval, @Param("proStatus") Integer proStatus);

    @Update("update project set pro_status = ${proStatus} where pro_id = #{proId}")
    void updateProStatusByProId(@Param("proId") String proId, @Param("proStatus") Integer proStatus);

    @Update("update project set pro_status = ${proStatus}, pro_approval = ${proApproval} where pro_id = #{proId}")
    void updateProsByProId(@Param("proId") String proId, @Param("proStatus") Integer proStatus, @Param("proApproval") Integer proApproval);

    /**
     * 添加延期原因
     *
     * @param proId      项目id
     * @param delayCause 延期原因
     * @return Integer
     */
    @Update("update project set delay_cause = #{delayCause} where pro_id = #{proId}")
    int addDelayCauseByProId(@Param("proId") String proId, @Param("delayCause") String delayCause);

    @Select("select delay_cause from project where pro_id = #{proId}")
    String getDelayCauseByProId(@Param("proId") String proId);

    @Select(
            "SELECT\n" +
                    "	pro_id \n" +
                    "FROM\n" +
                    "	`project` \n" +
                    "WHERE\n" +
                    "	batch_id = #{BatchId}"
    )
    List<String> getProIdByBatchId(@Param("BatchId") String batchId);


    @Select(
            "SELECT\n" +
                    "	project.batch_id \n" +
                    "FROM\n" +
                    "	project \n" +
                    "WHERE\n" +
                    "	project.pro_approval = #{approval} \n" +
                    "GROUP BY\n" +
                    "	batch_id"
    )
    List<String> getBatchIdByApproval(int approval);
}